package com.blog.springcloud.controller;

import com.blog.springcloud.entities.CommonResult;
import com.blog.springcloud.entities.Payment;
import com.blog.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author chenlin
 * @create 2021-01-06  11:34
 */
@RestController
@Slf4j
public class PaymentController {
    @Resource
    PaymentService paymentService;

    @PostMapping("/payment/create")
    public CommonResult create(@RequestBody Payment payment){
        int i = paymentService.create(payment);
        if (i!=0){
            return new CommonResult(200, "添加成功",i);
        }else {
            return new CommonResult(400, "添加失败");
        }
    }

    @GetMapping("/payment/get/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable("id") Long id){
        Payment paymentById = paymentService.getPaymentById(id);
        log.info("查询结果为："+paymentById+"giao");
        if (paymentById != null){
            return new CommonResult<Payment>(200,"查询成功",paymentById);
        }else {
            return new CommonResult<>(400, "查询失败");
        }
    }

}
